package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.yuejian_11.activity.TrainDetailActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.TrainCollectBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.TrainitemViewHolder;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by NEUSOFT on 2017/10/24.
 */

public class TrainCollectAdapter extends BaseListAdapter {
    public TrainCollectAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView=layoutInflater.inflate(R.layout.item_train_list,parent,false);
        TrainitemViewHolder holder=new TrainitemViewHolder(itemView);
        return holder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        TrainitemViewHolder trainitemViewHolder=(TrainitemViewHolder) holder;
        final TrainCollectBean trainCollectBean = (TrainCollectBean)data.get(position);
        final  int trainId=trainCollectBean.getT_id();
        final String trainPhone =trainCollectBean.getT_phone();
        final String trainName =trainCollectBean.getT_name();
        final String trainPicture = BASE_URI+"trainpicture/"+trainCollectBean.getT_picture();
        Picasso.with(context)
                .load(trainPicture)
                .into(trainitemViewHolder.imageView);
        trainitemViewHolder.trainNameView.setText(trainName);
        //跳转到培训列表
        trainitemViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, TrainDetailActivity.class);
                intent.putExtra("t_name",trainName);
                intent.putExtra("t_picture",trainPicture);
                intent.putExtra("t_phone",trainPhone);
                intent.putExtra("t_id",trainId);
                context.startActivity(intent);
            }
        });

    }
}
